home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Pascal Super Library
/
Pascal Super Library (CW International)(1997).bin
/
LIBRARY
/
PAS_0693
/
TCTACTOE.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-06-30
|
5KB
|
120 lines
{─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
Msg : 329 of 374
From : Mario Polycarpou 3:690/254.0 28 May 93 20:19
To : Zaimi Zaidin
Subj : SMART TIC TAC TOE
────────────────────────────────────────────────────────────────────────────────
By coincidence, I wrote a "tic tac toe" program only two days ago
for someone who had this to do for an assignment. There's one last
bug in the program which makes it announce a winner incorrectly.
You may need to spend an hour or two finding it as I beleive it
is an array coordinate mixup that is causing the problem....BTW...no
frills...its an assignment for a college kid..}
PROGRAM Assign;
USES Crt;
TYPE TicTacToe = Array[1..3,1..3] of Char;
VAR TTT:TicTacToe; Col,Row:Byte; Win:Boolean;
{-------------------------------------------------}
PROCEDURE Display;
BEGIN
Textattr:=$0F;
Gotoxy(25,2); Write ('TIC-TAC-TOE By George Mammen ');
Gotoxy(17,3); Write (' ══════════════════════════════════ ');
Gotoxy(17,4); Write (' ');
Gotoxy(17,5); Write ('╔═════════════════════════════════════════════╗');
Gotoxy(17,6); Write ('║ ║');
Gotoxy(17,7); Write ('║ │ │ ║');
Gotoxy(17,8); Write ('║ │ │ ║');
Gotoxy(17,9); Write ('║ │ │ ║');
Gotoxy(17,10); Write ('║ (1,1) │ (2,1) │ (3,1) ║');
Gotoxy(17,11); Write ('║ ───────────┼──────────┼─────────── ║');
Gotoxy(17,12); Write ('║ │ │ ║');
Gotoxy(17,13); Write ('║ │ │ ║');
Gotoxy(17,14); Write ('║ (1,2) │ (2,2) │ (3,2) ║');
Gotoxy(17,15); Write ('║ ───────────┼──────────┼─────────── ║');
Gotoxy(17,16); Write ('║ │ │ ║');
Gotoxy(17,17); Write ('║ │ │ ║');
Gotoxy(17,18); Write ('║ │ │ ║');
Gotoxy(17,19); Write ('║ (1,3) │ (2,3) │ (3,3) ║');
Gotoxy(17,20); Write ('║ ║');
Gotoxy(17,21); Write ('╚═════════════════════════════════════════════╝');
END; {Display}
{--------------------------}
PROCEDURE ClearArray;
BEGIN
FOR Col:=1 TO 3 DO
FOR Row:=1 TO 3 DO TTT[Col,Row]:=' ';
END;
{---------------------------------}
PROCEDURE ShowChars;
BEGIN
CASE Col OF
1: CASE Row OF
1: Gotoxy(28,8);
2: Gotoxy(28,12);
3: Gotoxy(28,17);
END;
2: CASE Row OF
1: Gotoxy(40,8);
2: Gotoxy(40,12);
3: Gotoxy(40,17);
END;
3: CASE Row OF
1: Gotoxy(51,8);
2: Gotoxy(51,12);
3: Gotoxy(51,17);
END;
END;
Write(TTT[row,col]);
END;
{------------------------------------------------------------------}
PROCEDURE CheckWin;
BEGIN
IF (TTT[1,1] = TTT[2,1]) THEN IF (TTT[1,1] = TTT[3,1]) THEN Win:=True;
IF (TTT[1,1] = TTT[1,2]) THEN IF (TTT[1,1] = TTT[1,3]) THEN Win:=True;
IF (TTT[1,1] = TTT[2,2]) THEN IF (TTT[1,1] = TTT[3,3]) THEN Win:=True;
IF (TTT[2,1] = TTT[2,2]) THEN IF (TTT[2,1] = TTT[2,3]) THEN Win:=True;
IF (TTT[3,1] = TTT[2,2]) THEN IF (TTT[3,1] = TTT[1,3]) THEN Win:=True;
IF (TTT[1,2] = TTT[2,2]) THEN IF (TTT[1,2] = TTT[3,2]) THEN Win:=True;
IF (TTT[3,1] = TTT[3,2]) THEN IF (TTT[3,1] = TTT[3,3]) THEN Win:=True;
IF (TTT[1,3] = TTT[2,3]) THEN IF (TTT[1,3] = TTT[3,3]) THEN Win:=True;
END;
{-------------------------------------------------}
PROCEDURE GetCords;
VAR Symbol1,Symbol2:Char; Player:Byte;
BEGIN
Player:=1; Win:=False;
Gotoxy(17,23);
Write ('Enter the Character for Player 1 (O or X) : ');
Readln(Symbol1);
Gotoxy(17,24);
Write ('Enter the Character for Player 2 (O or X) : ');
Readln(Symbol2);
REPEAT
Window(15,22,70,25); Clrscr; Window (1,1,80,25);
Gotoxy(2,22); Write ('Player : ',Player);
Gotoxy(20,22); Write ('Enter the Column (1/2/3) : ');
Readln(Col);
Gotoxy(20,23); Write ('Enter the Row (1/2/3) : ');
Readln(Row);
IF Player=1 THEN TTT[Row,Col]:=Symbol1 ELSE TTT[Row,Col]:=Symbol2;
IF Player=1 THEN Inc(Player) ELSE Player:=1;
ShowChars; CheckWin;
IF Win=True THEN
BEGIN
Gotoxy(20,25); Write ('We have a winner...');
END;
UNTIL Player=3;
END;
{-------------------------------------------------}
BEGIN
Textattr:=$07;
Clrscr;
ClearArray;
Display;
GetCords;
END. {That's it....hope you get something out of it...}